<form action="" class="form-horizontal" role="form">

	<div class="form-group">
		<label class="col-xs-2 control-label">商城名称</label>
		<div class="col-xs-3">
			<input type="text" class="form-control" name="name" placeholder="请输入商城名称" datatype="*" value="{$partnerProduct.name}">
		</div>
	</div>
	<div class="form-group">
		<label class="col-xs-2 control-label">联系电话</label>
		<div class="col-xs-3">
			<input type="text" class="form-control" name="tel" placeholder="请输入联系电话" datatype="*" value="{$partnerProduct.tel}">
		</div>
	</div>
	<div class="form-group">
		<label class="col-xs-2 control-label">分成设置<br/>
		<span class="label label-info">商品分成比例和为10（合作商:所有者:销售者）</span>
        </label>
		<div class="col-xs-4 productPercent">
			<input type="number" class="form-control" name="partnerProduct[percent][0]" placeholder="合作商" datatype="*" value="{$partnerProduct[percent][0]*1}" style="float:left;width:92px;" min="0" max="10">
      <span style="float: left; margin: 0px 3px; margin-top: 6px;">:</span>

			<input type="number" class="form-control" name="partnerProduct[percent][1]" placeholder="客户" datatype="*" value="{$partnerProduct[percent][1]*1}" style="float:left;width:92px;" min="0" max="10">
      <span style="float: left; margin: 0px 3px; margin-top: 6px;">:</span>

			<input type="number" class="form-control" name="partnerProduct[percent][2]" placeholder="销售者" datatype="*" value="{$partnerProduct[percent][2]*1}" style="float:left;width:92px;" min="0" max="10">
		</div>
	</div>
	<div class="form-group">
		<label class="col-xs-2 control-label">状态</label>
		<div class="col-xs-3">{$partnerProduct.status}</div>
	</div>
	<div class="form-group">
		<div class="col-xs-offset-2 col-xs-8">
			<input type="hidden" name="id" value="{$partnerProduct.id}"> <a
				class="btn btn-default" onclick="javascript:history.go(-1)">返回上页</a>
			<a class="btn btn-default" onclick="self.location=document.referrer">返回上页并刷新</a>
			<button type="submit" class="btn btn-primary submit"
				data-loading-txt="提交中，请稍后……" data-ajax-url="__CONTROLLER__/save">保存更改</button>
		</div>
	</div>
</form>

<script type="text/javascript">
  window.PercentCtl = {
			'percent' : [],
			'init' : function() {
				$(".productPercent input").each(function() {
					PercentCtl.percent.push($(this).val());
				});
				$(".productPercent input").change(function() {
					var percent = PercentCtl.percent;
					var i = $(".productPercent input").index(this);
					var currentValue = $(this).val()*1;
					if( currentValue > percent[i]*1 ) {
						var inc = currentValue*1 - percent[i]*1;
						var m = [];
						var t = 0;
						for(var j=i+1; j<percent.length; j++) {
						   t += percent[j]*1;
						   if ( t > inc ) {
							   m[j] = t - inc;
							   break;
						   } else if( t <= inc ) {
							   m[j] = 0;
						   }
						}
						if(t >= inc) {
							for (var o in m) PercentCtl.percent[o] = m[o]; 
							PercentCtl.percent[i] = $(this).val();
						}
					} else if( currentValue < percent[i] ) {
						var dec = percent[i]*1 - currentValue*1;
						var j = i+1;
						if ( j < percent.length ) {
							PercentCtl.percent[j] = PercentCtl.percent[j]*1+dec;
							PercentCtl.percent[i] = $(this).val();
						}
					}
					PercentCtl.updateData();
				});
			},
			'updateData' : function() {
				$(".productPercent input").each(function(i) {
					$(this).val(PercentCtl.percent[i]*1);
				});
			}
  };
  PercentCtl.init();
</script>